import java.util.ArrayList;
import java.util.Collections;

public class LinkerSymbolTable extends ArrayList<LinkerSymbol> {

	LinkerSymbolTable () {
	}
	
	public void defineSymbol (LinkerSymbol symb) {
		this.add(symb);
	}
	
	public boolean symbolIsDefined(String label){	
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				return true;
			}
		}
		return false;
	}
	
	public boolean updateAsmLocation (String label, String location) {
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				s.setAsmLocation(location);
				return true;
			}
		}
		return false;
	}
	
	public boolean updateLinkerLocation (String label, String location) {
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				s.setLinkerLocation(location);
				return true;
			}
		}
		return false;
	}
	
	public boolean updateRelocationValue (String label, String location) {
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				s.setRelocationValue(location);
				return true;
			}
		}
		return false;
	}
	
	public LinkerSymbol getSymbol (String label) {
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				LinkerSymbol symb = new LinkerSymbol(s.getLabel(), s.getLoadAddress(), s.getAsmLocation(), s.getLinkerLocation(), s.getLength(), s.getRelocationValue(), s.getExecutionStart());
				return symb;
			}
		}
		LinkerSymbol symb = new LinkerSymbol();
		return symb;
	}
	
	public String getAsmLocation (String label){
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				return s.getAsmLocation();
			}
		}
		return "";
	}
	
	public String getLinkerLocation(String label) {
		String location = "";
		for (LinkerSymbol s : this) {
			if (s.getLabel().equals(label)) {
				location = s.getLinkerLocation();
			}
		}
		return location;
	}
	
	public String getAdjustment(String label) {
		String adjust = "";
		for (LinkerSymbol s : this) {
			if (s.getLabel().equals(label)) {
				adjust = s.getRelocationValue();
			}
		}
		return adjust;
	}
	public String getLength (String label){
		for(LinkerSymbol s : this){
			if(s.getLabel().equals(label)){
				return s.getLength();
			}
		}
		return "";
	}
}
